package com.xhz.reload;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;

public class Helper {
    private Helper(){}
	public static Method getMethod(Class<?> cls, String methodName, Class<?>...classes) {
		Method method = null;
		for (Class<?> clazz = cls; clazz !=Object.class; clazz = clazz.getSuperclass() ) {
			try {
				method = clazz.getDeclaredMethod(methodName, classes);
			} catch (NoSuchMethodException e) {
				e.printStackTrace();
			}
		}
		return method;
	}
	
	public static byte[] toBytes(InputStream is) throws IOException {
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		byte[] temp = new byte[1000];
		int n;
		while ((n = is.read(temp)) != -1) {
			bos.write(temp, 0 ,n);
		}
		is.close();
		bos.close();
		return bos.toByteArray();
	}
}